import Vue from 'vue'
import Router from 'vue-router'

// in development-env not use lazy-loading, because lazy-loading too many pages will cause webpack hot update too slow. so only in production use lazy-loading;
// detail: https://panjiachen.github.io/vue-element-admin-site/#/lazy-loading

Vue.use(Router)

/* Layout */
import Layout from '../views/admin/layout/Layout'
import TeacherLayout from '../views/teacher/layout/Layout'
import StudentLayout from '../views/student/layout/Layout'

/**
 * hidden: true                   if `hidden:true` will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu, whatever its child routes length
 *                                if not set alwaysShow, only more than one route under the children
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noredirect           if `redirect:noredirect` will no redirct in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    title: 'title'               the name show in submenu and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar,
  }
 **/
export const constantRouterMap = [
  {path: '/login', component: () => import('@/views/student/login/index'), hidden: true},
  {path: '/adminlogin', component: () => import('@/views/admin/login/index'), hidden: true},
  {path: '/teacherlogin', component: () => import('@/views/teacher/login/index'), hidden: true},

  {path: '/404', component: () => import('@/views/404'), hidden: true},

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    name: 'Dashboard',
    hidden: true,
    children: [{
      path: 'dashboard',
      component: () => import('@/views/admin/dashboard/index')
    }]
  },

  {
    path: '/admin',
    component: Layout,
    redirect: '/admin/dashboard',
    name: 'dashboard',
    meta: {role: 'admin', title: 'Dashboard', icon: 'dashboard'},
    children: [
      {
        path: 'dashboard',
        name: 'dashboard',
        component: () => import('@/views/admin/dashboard/index'),
        meta: {role: 'admin', title: '首页', icon: 'menu'}
      }
    ]
  },
  {
    path: '/admin/teacher',
    component: Layout,
    redirect: '/admin/teacher/list',
    name: 'adminteacher',
    meta: {role: 'admin', title: '教师管理', icon: 'dashboard'},
    children: [
      {
        path: 'list',
        name: 'teacherlist',
        component: () => import('@/views/admin/teacher/list'),
        meta: {role: 'admin', title: '教师列表', icon: 'tree'}
      },
      {
        path: 'add',
        name: 'teacheradd',
        component: () => import('@/views/admin/teacher/add'),
        meta: {role: 'admin', title: '添加教师', icon: 'add'}
      },

    ]
  },
  {
    path: '/admin/student',
    component: Layout,
    redirect: '/admin/student/list',
    name: 'adminstudent',
    meta: {role: 'admin', title: '学生管理', icon: 'dashboard'},
    children: [
      {
        path: 'list',
        name: 'studentlist',
        component: () => import('@/views/admin/student/list'),
        meta: {role: 'admin', title: '学生列表', icon: 'tree'}
      },
      {
        path: 'add',
        name: 'teacheradd',
        component: () => import('@/views/admin/student/add'),
        meta: {role: 'admin', title: '添加学生', icon: 'add'}
      },

    ]
  },
  {
    path: '/admin/classroom',
    component: Layout,
    redirect: '/admin/classroom/list',
    name: 'adminclassroom',
    meta: {role: 'admin', title: '班级管理', icon: 'dashboard'},
    children: [
      {
        path: 'list',
        name: 'classroomlist',
        component: () => import('@/views/admin/classroom/list'),
        meta: {role: 'admin', title: '班级列表', icon: 'tree'}
      },
      {
        path: 'add',
        name: 'classroomadd',
        component: () => import('@/views/admin/classroom/add'),
        meta: {role: 'admin', title: '添加班级', icon: 'add'}
      },

    ]
  },
  {
    path: '/admin/paper',
    component: Layout,
    redirect: '/admin/paper/list',
    name: 'adminpaper',
    meta: {role: 'admin', title: '试卷管理', icon: 'dashboard'},
    children: [
      {
        path: 'list',
        name: 'paperlist',
        component: () => import('@/views/admin/paper/list'),
        meta: {role: 'admin', title: '试卷列表', icon: 'tree'}
      },
      {
        path: 'add',
        name: 'paperadd',
        component: () => import('@/views/admin/paper/add'),
        meta: {role: 'admin', title: '添加试卷', icon: 'add'}
      },
      {
        path: 'answerlist',
        name: 'answerresultlist',
        component: () => import('@/views/admin/answerresult/list'),
        meta: {role: 'admin', title: '答卷列表', icon: 'list'}
      },

    ]
  },
  {
    path: '/admin/question',
    component: Layout,
    redirect: '/admin/question/list',
    name: 'adminquestion',
    meta: {role: 'admin', title: '题目管理', icon: 'dashboard'},
    children: [
      {
        path: 'list',
        name: 'questionlist',
        component: () => import('@/views/admin/question/list'),
        meta: {role: 'admin', title: '题目列表', icon: 'null'}
      }
    ]
  },

  {
    path: '/teacher',
    component: TeacherLayout,
    redirect: '/teacher/dashboard',
    name: 'teacherdashboard',
    meta: {role: 'teacher', title: 'Dashboard', icon: 'dashboard'},
    children: [
      {
        path: 'dashboard',
        name: 'teacherdashboard',
        component: () => import('@/views/teacher/dashboard/index'),
        meta: {role: 'teacher', title: '首页', icon: 'menu'}
      }
    ]
  },
  {
    path: '/teacher/paper',
    component: TeacherLayout,
    redirect: '/teacher/paper/list',
    name: 'teacherpaper',
    meta: {role: 'teacher', title: '试卷管理', icon: 'dashboard'},
    children: [
      {
        path: 'list',
        name: 'paperlist',
        component: () => import('@/views/teacher/paper/list'),
        meta: {role: 'teacher', title: '试卷列表', icon: 'tree'}
      },


    ]
  },
  {
    path: '/teacher/paper',
    component: TeacherLayout,
    redirect: '/teacher/paper/list',
    name: 'teacherpaper',
    meta: {role: 'teacher', title: '试卷管理', icon: 'dashboard'},
    children: [
      {
        path: 'add',
        name: 'paperadd',
        component: () => import('@/views/teacher/paper/add'),
        meta: {role: 'teacher', title: '添加试卷', icon: 'add'}
      },
    ]
  },
  {
    path: '/teacher/paper',
    component: TeacherLayout,
    redirect: '/teacher/paper/list',
    name: 'teacherpaper',
    meta: {role: 'teacher', title: '试卷管理', icon: 'dashboard'},
    children: [
      {
        path: 'answerlist',
        name: 'answerresultlist',
        component: () => import('@/views/teacher/paper/answerresultlist'),
        meta: {role: 'teacher', title: '答卷列表', icon: 'list'}
      },
    ]
  },
  {
    path: '/teacher/classroom',
    component: TeacherLayout,
    redirect: '/teacher/classroom/list',
    name: 'teacherpaper',
    meta: {role: 'teacher', title: '班级管理', icon: 'dashboard'},
    children: [
      {
        path: 'list',
        name: 'teacherclassroomlist',
        component: () => import('@/views/teacher/paper/classroomlist'),
        meta: {role: 'teacher', title: '班级列表', icon: 'list'}
      },
    ]
  },

  {
    path: '/student/',
    component: StudentLayout,
    redirect: '/student/index',
    name: 'studentindex',
    meta: {role: 'student', title: '首页', icon: 'dashboard'},
    children: [
      {
        path: 'index',
        name: 'mainindex',
        component: () => import('@/views/student/index/index'),
        meta: {role: 'student', title: '首页', icon: 'list'}
      },
    ]
  },

  {
    path: '/student/',
    component: StudentLayout,
    redirect: '/student/index',
    name: 'mystudy',
    meta: {role: 'student', title: '我的学习', icon: 'dashboard'},
    children: [
      {
        path: 'mystudy',
        name: 'mystudycenter',
        component: () => import('@/views/student/mystudy/index'),
        meta: {role: 'student', title: '我的学习', icon: 'list'}
      },
    ]
  },
  {
    path: '/student/',
    component: StudentLayout,
    redirect: '/student/index',
    name: 'userquestioncenter',
    meta: {role: 'student', title: '个人中心', icon: 'dashboard'},
    children: [
      {
        path: 'mycenter',
        name: 'mycenter',
        component: () => import('@/views/student/mycenter/index'),
        meta: {role: 'student', title: '个人中心', icon: 'list'}
      },
    ]
  },
  {
    path: '/student/',
    component: StudentLayout,
    redirect: '/student/index',
    name: 'questionpage',
    meta: {role: 'student', title: '问答中心', icon: 'dashboard'},
    hidden: true,
    children: [
      {
        path: 'question',
        name: 'question',
        component: () => import('@/views/student/question/index'),
        meta: {role: 'student', title: '问答中心', icon: 'list'},
        hidden: true
      },
    ]
  },
  {path: '*', redirect: '/404', hidden: true}
]

export default new Router({
  // mode: 'history', //后端支持可开
  scrollBehavior: () => ({y: 0}),
  routes: constantRouterMap
})

